using System;
using System.Data;
using System.Data.SqlClient;
using Entity;

namespace SalesVMT
{
    public class BackupDB
    {
        
        public static bool Create(string LinkName)
        {
            bool retVal = false;         

            SqlConnection dbConn = SQLServerUtil.CreateConnectionBackup();
            SqlCommand dbCmd = new SqlCommand("CreateBackup", dbConn);
            dbCmd.Parameters.AddWithValue("@LinkName", LinkName);

            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                dbConn.Open();
                    dbCmd.ExecuteNonQuery();
                    retVal = true;
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
     
        public static bool Restore(string LinkName)
        {
            bool retVal = false;
            SqlConnection dbConn = SQLServerUtil.CreateConnectionBackup();
            SqlCommand dbCmd = new SqlCommand("RestoreBackup", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.AddWithValue("@LinkName", LinkName);
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                retVal = true;
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
        public static bool Disconnect()
        {
            bool retVal = false;
            SqlConnection dbConn = SQLServerUtil.CreateConnectionBackup();
            SqlCommand dbCmd = new SqlCommand("DisconnectBackup", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                retVal = true;
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
    }
}
